﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace font_dec
{
    class Program
    {
        static void Main(string[] args)
        {
            FileStream fsi = File.Open(args[0], FileMode.Open, FileAccess.Read);
            FileStream fso = File.Open(args[1], FileMode.Create, FileAccess.Write);
            BinaryReader br = new BinaryReader(fsi);
            BinaryWriter bw = new BinaryWriter(fso);
            int count = br.ReadInt16();
            for (int i=0;i<count;i++)
            {
                int offset=br.ReadInt32();

                Console.WriteLine(i);
                byte[] buf=font_decode(br, offset+count*4+2);
                bw.Write(buf, 0, 0x7 * 0xE);
            }
            bw.Close();
        }
        private static byte[] font_decode(BinaryReader br, int offset)
        {
            long pos2=br.BaseStream.Position;
            int pos = 0;
            byte[] ret=new byte[0x200];
            byte[] ret2=new byte[0x7*0xE];
            int[] oft=new int[14];
            int[] cnt=new int[14];
            br.BaseStream.Seek(offset+0x10,SeekOrigin.Begin);
            for (int i = 0; i < 14; i++)
            {
                oft[i] = br.ReadInt16();
                cnt[i] = br.ReadInt16();
            }
            foreach (int c in cnt)
            {
                byte b1, b2;
                int rep;
                for (int i = 0; i < c; i++)
                {
                    b1 = br.ReadByte();
                    rep = b1 & 0xF;
                    for (int j = 0; j < rep; j++) ret[pos++] = 0;
                    i++;
                    if (i >= c) break;
                    rep = br.ReadByte();
                    for (int j = 0; j < rep; j++)
                    {
                        b2 = br.ReadByte();
                        ret[pos++] = (byte)(b2 & 0xF);
                        b2 >>= 4;
                        j++;
                        if (j >= rep) break;
                        ret[pos++] = (byte)(b2 & 0xF);
                    }
                }
            }
            br.BaseStream.Seek(pos2,SeekOrigin.Begin);
            int i2=0;
            for (int i = 0; i < pos; i++)
            {
                int b = ret[i] & 0xF;
                b <<= 4;
                i++;
                b += ret[i];
                ret2[i2++] = (byte)b;
                if (i2 >= 0x7 * 0xE) break;
            }
            return ret2;
        }
    }
}
